import { check } from 'meteor/check';
import { Notifications } from '/imports/models/Notifications';

Meteor.methods({
  markRead(id) {
    check(id, String);
    return Notifications.update({_id: id}, {$set: {
      read: true
    }});
  },

  markUnread(id) {
    check(id, String);
    return Notifications.update({_id: id}, {$set: {
      read: false
    }});
  },

  markAllRead() {
    return Notifications.update(
      {user_id: Meteor.userId(), read: false}, 
      {$set: { read: true }},
      {multi: true}
    );
  },

  deleteNotification(id) {
    check(id, String);
    return Notifications.remove({
      _id: id
    });
  }
});